package com.eightbears.beboy.base.view.image.view;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ImageItem implements Serializable {

    public static final String TYPE_NET_IMAGE = "net";

    public String name;       //图片的名字
    public String path;       //图片的路径
    public String type = "";
    public int imageRes;      //图片资源
    public long size;         //图片的大小
    public int width;         //图片的宽度
    public int height;        //图片的高度
    public String mimeType;   //图片的类型
    public long addTime;      //图片的创建时间

    public ImageItem() {

    }

    public ImageItem(String path) {
        this.path = path;
    }


    public ImageItem(int imageRes) {
        this.imageRes = imageRes;
    }

    public ImageItem(String imagePath, String imgType) {
        this.path = imagePath;
        this.type = imgType;
    }


    /**
     * 图片的路径和创建时间相同就认为是同一张图片
     */
    @Override
    public boolean equals(Object o) {
        try {
            ImageItem other = (ImageItem) o;
            return this.path.equalsIgnoreCase(other.path) && this.addTime == other.addTime;
        } catch (ClassCastException e) {
            e.printStackTrace();
        }
        return super.equals(o);
    }

    public static List<ImageItem> replaceImage(List<String> images) {
        List<ImageItem> imageItems = new ArrayList<>();
        if (images != null) {
            for (int i = 0; i < images.size(); i++) {
                ImageItem imageItem = new ImageItem();
                imageItem.path = images.get(i);
                imageItem.type = "net";
                imageItems.add(imageItem);
            }
        }
        return imageItems;
    }

    @Override
    public String toString() {
        return "ImageItem{" +
                "name='" + name + '\'' +
                ", path='" + path + '\'' +
                ", type='" + type + '\'' +
                ", imageRes=" + imageRes +
                ", size=" + size +
                ", width=" + width +
                ", height=" + height +
                ", mimeType='" + mimeType + '\'' +
                ", addTime=" + addTime +
                '}';
    }
}
